package com.lagou.testpool;

import com.lagou.Utils.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TestDruid {
    //需求 查询 薪资在3000-5000的员工的姓名
    public static void main(String[] args) throws Exception {
        //1.获取连接
        Connection connection= DruidUtils.getConnection();

        //2.获取预处理对象
        PreparedStatement preparedStatement=connection.prepareStatement("select ename from employee where salary between ? and ?");

        //3.设置占位符的值
        preparedStatement.setDouble(1,3000.0);
        preparedStatement.setDouble(2,5000.0);
        ResultSet resultSet=preparedStatement.executeQuery();


        //4.处理结果集
        while(resultSet.next()){
        String ename=resultSet.getString("ename");
        System.out.println("薪资在3000-5000的员工的姓名:"+ename);
        }

        //5.释放资源
        DruidUtils.close(connection,preparedStatement,resultSet);
    }
}
